﻿<template>
	<div class="card-fill layout-padding" v-loading="loading" element-loading-text="Loading...">
		<el-card shadow="hover" class="layout-padding-auto create-form">
			<el-form ref="formRef" :model="stateData.vmModel" label-width="100px">
				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>访客信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_Name_FormItem" prop="Entity.Name" :rules="[{ required: true, message: '姓名为必填项', trigger: 'blur' }]">
								<template #label>
									<WtmLabelTooltip label="姓名" tooltip="访客姓名" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.Name" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_Phone_FormItem" prop="Entity.Phone" :rules="[{ required: true, message: '手机号为必填项', trigger: 'blur' }]">
								<template #label>
									<WtmLabelTooltip label="手机号" tooltip="访客手机号" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.Phone" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item
								ref="Entity_IdCardNo_FormItem"
								prop="Entity.IdCardNo"
								:rules="[{ required: true, message: '身份证号为必填项', trigger: 'blur' }]"
							>
								<template #label>
									<WtmLabelTooltip label="身份证号" tooltip="访客身份证号" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.IdCardNo" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>身份信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_IdCardFrontPhotoId_FormItem" prop="Entity.IdCardFrontPhotoId">
								<template #label>
									<WtmLabelTooltip label="身份证人像面" tooltip="身份证人像面文件" />
								</template>
								<wtm-upload-image v-model="stateData.vmModel.Entity.IdCardFrontPhotoId" disabled clearable class="width100"></wtm-upload-image>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_IdCardBackPhotoId_FormItem" prop="Entity.IdCardBackPhotoId">
								<template #label>
									<WtmLabelTooltip label="身份证国徽面" tooltip="身份证国徽面文件" />
								</template>
								<wtm-upload-image v-model="stateData.vmModel.Entity.IdCardBackPhotoId" disabled clearable class="width100"></wtm-upload-image>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>访客信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_Company_FormItem" prop="Entity.Company">
								<template #label>
									<WtmLabelTooltip label="所属单位/公司" tooltip="访客所属单位或公司" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.Company" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_CarNo_FormItem" prop="Entity.CarNo">
								<template #label>
									<WtmLabelTooltip label="车牌号" tooltip="访客车辆车牌号" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.CarNo" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>系统用户绑定</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_UserId_FormItem" prop="Entity.UserId">
								<template #label>
									<WtmLabelTooltip label="绑定用户" tooltip="关联的系统用户对象" />
								</template>
								<el-select v-model="stateData.vmModel.Entity.UserId" disabled clearable class="width100">
									<el-option v-for="item in stateData.AllFrameworkUsers" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>访客信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_Remark_FormItem" prop="Entity.Remark">
								<template #label>
									<WtmLabelTooltip label="备注信息" tooltip="备注信息" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.Remark" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div class="form-section">
					<div class="section-title">
						<i class="_wtmicon _wtmicon-wxbzhanghu"></i>
						<span>黑名单信息</span>
					</div>

					<el-row :gutter="20">
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item
								ref="Entity_BlackStatus_FormItem"
								prop="Entity.BlackStatus"
								:rules="[{ required: true, message: '黑名单状态为必填项', trigger: 'blur' }]"
							>
								<template #label>
									<WtmLabelTooltip label="黑名单状态" tooltip="黑名单状态" />
								</template>
								<el-select v-model="stateData.vmModel.Entity.BlackStatus" disabled clearable class="width100">
									<el-option :key="1" :value="true" :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
									<el-option :key="0" :value="false" :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :lg="12" class="mb20">
							<el-form-item ref="Entity_BlackReason_FormItem" prop="Entity.BlackReason">
								<template #label>
									<WtmLabelTooltip label="黑名单原因" tooltip="黑名单原因" />
								</template>
								<el-input v-model="stateData.vmModel.Entity.BlackReason" disabled clearable class="width100"></el-input>
							</el-form-item>
						</el-col>
					</el-row>
				</div>

				<div style="text-align: right">
					<WtmButton @click="onClose" type="default" :button-text="$t('message._system.common.vm.cancel')" style="margin-top: 15px" />
				</div>
			</el-form>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="message._system.common.vm.edit;false">
import { reactive, ref, getCurrentInstance, onMounted, computed } from 'vue';
import { ElMessage } from 'element-plus';
import { SysVisitorInformationApi as api } from '/@/views/visitor/sysvisitorinformation/api';
import other from '/@/utils/other';
import { useRouter } from 'vue-router';
import { ISysVisitorInformationVm } from '/@/views/visitor/sysvisitorinformation/api/interface';
import { IViewModel } from '/@/types/common';

const ci = getCurrentInstance() as any;
const loading = ref(false);
// 定义变量内容
const formRef = ref();
const stateData = reactive<IViewModel<ISysVisitorInformationVm>>({
	vmModel: {
		Entity: {
			ID: null,
			Name: null,
			Phone: null,
			IdCardNo: null,
			IdCardFrontPhotoId: null,
			IdCardBackPhotoId: null,
			Company: null,
			CarNo: null,
			UserId: null,
			Remark: null,
			BlackStatus: false,
			BlackReason: null,
		},
	},

	AllFrameworkUsers: [] as any[],
});

// 取消
const onClose = () => {
	closeDialog();
};

// 页面加载时
onMounted(() => {
	loading.value = true;
	if (ci.attrs['wtmdata']) {
		stateData.vmModel.Entity.ID = ci.attrs['wtmdata'].ID;
	} else if (useRouter().currentRoute.value.query.id) {
		stateData.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	const promises: Promise<any>[] = [
		other.getSelectList('/api/SysVisitorInformation/GetFrameworkUsers', [], false).then((x) => {
			stateData.AllFrameworkUsers = x;
		}),

		api()
			.get(stateData.vmModel.Entity.ID ?? '')
			.then((data: any) => other.setValue(stateData.vmModel, data)),
	];
	Promise.allSettled(promises).finally(() => {
		loading.value = false;
	});
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh', 'closeDialog']);
// 关闭弹窗
const closeDialog = () => {
	emit('closeDialog');
};
</script>
